{
 "metadata": {
  "name": "",
  "signature": "sha256:b0230e2c391d363a04ed8d177db84780f6641a74753aba55aa1cbdbb0c8497a5"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "# The Generalised Linear Model\n",
      "\n",
      "## A practical introduction using the Python environment\n",
      "\n",
      "[Tom Wallis](http://www.tomwallis.info) and [Philipp Berens](http://philippberens.wordpress.com/)\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "This course provides an overview of an extremely flexible\n",
      "statistical framework for describing and performing inference with a wide\n",
      "variety of data types: the Generalised Linear Model (GLM). Many common statistical procedures are special cases of the GLM. In the course, we focus on the construction and understanding of design matrices and the interpretation of regression weights. We mostly concentrate on the linear Gaussian model, before discussing more general cases. We also touch on how this framework relates to ANOVA-style model comparison.\n",
      "\n",
      "The course was designed and presented as a six week elective statistics course for graduate students in the neuroscience program at the University of T\u00fcbingen, in January 2015. Lectures were presented as a collection of IPython Notebooks. While the notebooks are (we hope) well documented, they *are* lecture materials rather than a textbook. As such, some content might not be self-explanatory. \n",
      "\n",
      "We chose to do the course in Python because \n",
      "\n",
      "1. It is a general purpose programming language and thus more versatile than e.g. [R](http://cran.r-project.org/). Neuroscientists can use Python to not only analyse data but also to e.g. interface with hardware, [conduct behavioural experiments](http://www.psychopy.org/), etc. \n",
      "1. Its [popularity as a scientific computing environment is rapidly growing](http://www.nature.com/news/programming-pick-up-python-1.16833).\n",
      "1. The scientific computing environment of Python has many similarities to MATLAB &trade;, which is the historically dominant environment in our field.\n",
      "1. It is free and open source, and thus we feel will continue to benefit students who move out of a university environment. \n",
      "\n",
      "Nevertheless, the main statistical module we use here (`Statsmodels`) is well behind R in its maturity (no wonder, since R is a *lot* older). Thankfully, learning to create and interpret design matrices using `Patsy` formula notation is a skill that transfers easily to R's `glm` routines. \n",
      "\n",
      "Note two things:\n",
      "\n",
      "1. *This is not a programming course*. If you do not have enough experience with programming (or Python) to follow the materials here, seek out an introduction to programming in Python. There are many available for free on the internet.\n",
      "1. *This is not a basic statistics course*. You should be reasonably familiar with things like t-tests and ANOVA before proceeding.\n",
      "\n",
      "Where content is erroneous, unclear or buggy, please tell us at our [GitHub repository](https://github.com/tomwallis/glm-intro)."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## Lectures"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "1. [Dataframes and Exploratory Plotting](lectures/dataframes_plots.ipynb)\n",
      "1. [Introduction to design matrices](lectures/design_matrices.ipynb)\n",
      "    1. [Homework solution](lectures/homework_solution_1.ipynb)\n",
      "1. [Interactions](lectures/Interactions.ipynb)\n",
      "1. [ANOVA](lectures/ANOVA.ipynb)\n",
      "1. [Link functions](lectures/link_functions.ipynb)"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## Datasets\n",
      "\n",
      "To demonstrate the ideas in the course we used several datasets obtained from the [OzDASL database](http://www.statsci.org/data/index.html) as well as from our own research. They are provided in the git repository to facilitate self learning."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## License"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "**Authors:** [Tom Wallis](http://www.tomwallis.info) and [Philipp Berens](http://philippberens.wordpress.com/)\n",
      "\n",
      "**Year:** 2015 \n",
      "\n",
      "**Copyright:** This work is licensed under a [CC-by-4.0](https://creativecommons.org/licenses/by/4.0/) license. You may reuse, modify and redistribute these materials provided you give appropriate credit to the authors. All images embedded in the lecture materials were obtained from the internet and are used under \"fair use\" for educational purposes. The copyright for all images remain with their respective holders."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## Further reading\n",
      "\n",
      "Here we provide some references for further reading. These reflect our own backgrounds in neuroscience and psychology.\n",
      "\n",
      "Burnham, K. P., & Anderson, D. R. (2002). Model selection and multimodel inference a practical information-theoretic approach. New York: Springer. \n",
      " - *A thorough overview of model comparison, which is how we like to think of ANOVA*\n",
      "\n",
      "Gelman, A., & Hill, J. (2007). Data Analysis using regression and multilevel/hierarchical models. New York, NY: Cambridge Univ Press.\n",
      "- *Introduction to regression using multilevel models. Random effects models, pooling and shrinkage...*\n",
      "\n",
      "Knoblauch, K., & Maloney, L. T. (2012). Modeling Psychophysical Data in R. New York: Springer. \n",
      "- *This book presents some clear examples of applying GLMs to modelling psychophysical data, using the R environment*\n",
      "\n",
      "Kruschke, J. K. (2011). Doing Bayesian Data Analysis. Academic Press / Elsevier. \n",
      "- *The last half of this book is dedicated to a clear and thorough practical introduction to GLMs. We recommend the Bayesian inference stuff too, but it's not part of our course*\n",
      "\n",
      "Wickham, H. (2014). Tidy Data. Journal of Statistical Software, 59(10), ??\u2013?? \n",
      "- *An article about how to arrange data so that analysis environments like Pandas can work with it.*\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "--------------------------------\n",
      "\n",
      "[Here are some notes](setup_python.ipynb) on how we set up a Python environment for the course (packages, versions) etc."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from IPython.core.display import HTML\n",
      "\n",
      "\n",
      "def css_styling():\n",
      "    styles = open(\"custom_style.css\", \"r\").read()\n",
      "    return HTML(styles)\n",
      "css_styling()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "html": [
        "<style>\n",
        "    @font-face {\n",
        "        font-family: \"Computer Modern\";\n",
        "        src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunss.otf');\n",
        "    }\n",
        "    @font-face {\n",
        "        font-family: \"Computer Modern\";\n",
        "        font-weight: bold;\n",
        "        src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunsx.otf');\n",
        "    }\n",
        "    @font-face {\n",
        "        font-family: \"Computer Modern\";\n",
        "        font-style: oblique;\n",
        "        src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunsi.otf');\n",
        "    }\n",
        "    @font-face {\n",
        "        font-family: \"Computer Modern\";\n",
        "        font-weight: bold;\n",
        "        font-style: oblique;\n",
        "        src: url('http://9dbb143991406a7c655e-aa5fcb0a5a4ec34cff238a2d56ca4144.r56.cf5.rackcdn.com/cmunso.otf');\n",
        "    }\n",
        "    div.cell{\n",
        "        width:850px;\n",
        "        font-size: 11pt;\n",
        "        margin-left:16% !important;\n",
        "        margin-right:auto;\n",
        "    }\n",
        "    h1 {\n",
        "        font-family: Minion Pro, serif;\n",
        "    }\n",
        "    h2 {\n",
        "        font-family: Minion Pro, serif;\n",
        "    }\n",
        "    h3 {\n",
        "        font-family: Minion Pro, serif;\n",
        "    }\n",
        "    h4{\n",
        "        margin-top:12px;\n",
        "        margin-bottom: 3px;\n",
        "       }\n",
        "    div.text_cell_render{\n",
        "        font-family: Optima, sans-serif;\n",
        "        line-height: 145%;\n",
        "        font-size: 12pt;\n",
        "        width:850px;\n",
        "        margin-left:auto;\n",
        "        margin-right:auto;\n",
        "    }\n",
        "    .CodeMirror{\n",
        "            font-family: \"Source Code Pro\", source-code-pro,Consolas, monospace;\n",
        "    }\n",
        "    .prompt{\n",
        "        display: None;\n",
        "    }\n",
        "    .text_cell_render h5 {\n",
        "        font-weight: 300;\n",
        "        font-size: 12pt;\n",
        "        color: #4057A1;\n",
        "        font-style: italic;\n",
        "        margin-bottom: .5em;\n",
        "        margin-top: 0.5em;\n",
        "        display: block;\n",
        "    }\n",
        "\n",
        "    .warning{\n",
        "        color: rgb( 240, 20, 20 )\n",
        "        }\n",
        "</style>\n",
        "<script>\n",
        "    MathJax.Hub.Config({\n",
        "                        TeX: {\n",
        "                           extensions: [\"AMSmath.js\"]\n",
        "                           },\n",
        "                tex2jax: {\n",
        "                    inlineMath: [ ['$','$'], [\"\\\\(\",\"\\\\)\"] ],\n",
        "                    displayMath: [ ['$$','$$'], [\"\\\\[\",\"\\\\]\"] ]\n",
        "                },\n",
        "                displayAlign: 'center', // Change this to 'center' to center equations.\n",
        "                \"HTML-CSS\": {\n",
        "                    styles: {'.MathJax_Display': {\"margin\": 4}}\n",
        "                }\n",
        "        });\n",
        "</script>"
       ],
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 1,
       "text": [
        "<IPython.core.display.HTML at 0x106e0d9b0>"
       ]
      }
     ],
     "prompt_number": 1
    }
   ],
   "metadata": {}
  }
 ]
}